<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24" align="center">
        <el-button class="el-button--danger" size="small" v-hasPermi="['teamUserManager:setSystemConfig']"
          @click="setCallOutFuncConfig">{{ callPhoneText }}</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealSelfReceiveFlag']" @click="batchDealSelfReceiveFlag(1)"
          class="el-button--success" size="small">放开自助接收按钮</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealSelfReceiveFlag']" @click="batchDealSelfReceiveFlag(0)"
          class="el-button--danger" size="small">关闭自助接收按钮</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealSelfCloseFlag']" @click="batchDealSelfCloseFlag(1)"
          class="el-button--success" size="small">放开自助暂停按钮</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealSelfCloseFlag']" @click="batchDealSelfCloseFlag(0)"
          class="el-button--danger" size="small">关闭自助暂停按钮</el-button>
      </el-col>
    </el-row>
    <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" label-width="5px">
      <el-row style="margin-top: 10px">
        <el-col :span="3">

          <el-form-item>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="" prop="roleKey">
            <el-select v-model="queryParams.roleKey" placeholder="- 角色 -" filterable clearable>
              <el-option label="实习部长" value="internSupervisor"></el-option>
              <el-option label="部长" value="manager"></el-option>
              <el-option label="团队长" value="areaLeader"></el-option>
              <el-option label="客服" value="salesman"></el-option>
              <el-option label="学徒" value="apprentice"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="" prop="receiveNew">
            <el-select v-model="queryParams.receiveNew" placeholder="- 是否接收新数据 -" filterable clearable>
              <el-option label="是" value="1"></el-option>
              <el-option label="否" value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="" prop="isForceClose">
            <el-select v-model="queryParams.isForceClose" placeholder="- 是否强制关闭数据接收 -" filterable clearable>
              <el-option label="是" value="1"></el-option>
              <el-option label="否" value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="" prop="deptId">
            <treeselect v-model="queryParams.deptId" :options="deptOptions" :show-count="true" placeholder="请选择部门归属"  :default-expand-level="4" />
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="" prop="userId">
            <el-select v-model="queryParams.userId" placeholder="顾问" clearable filterable>
              <el-option v-for="user in sysUsersList" :key="user.userId" :label="user.nickName" :value="user.userId" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" style="margin-top: 10px">
      <el-col :span="24" align="center">
        <el-button v-hasPermi="['teamUserManager:batchSetDailyLimit']" @click="batchSetDailyLimit"
          class="el-button--danger" size="mini">调整日分配量</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealStatus']" @click="batchDealStatus(0)" class="el-button--success"
          size="mini">允许登录</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealStatus']" @click="batchDealStatus(1)" class="el-button--danger"
          size="mini">禁止登录</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealReceive']" @click="batchDealReceive(1)"
          class="el-button--success" size="mini">开放数据接收</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealReceive']" @click="batchDealReceive(0)"
          class="el-button--danger" size="mini">关闭数据接收</el-button>
        <el-button class="el-button--success" @click="batchDealSelfReceiveStatus(1)" size="mini">开始自助接收数据</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealDataFetch']" @click="batchDealDataFetch(0)"
          class="el-button--success" size="mini">开启数据抓取</el-button>
        <el-button v-hasPermi="['teamUserManager:batchDealDataFetch']" @click="batchDealDataFetch(1)"
          class="el-button--danger" size="mini">暂停数据抓取</el-button>
        <el-button v-hasPermi="['teamUserManager:batchSetTotalLimit']" @click="batchSetTotalLimit"
          class="el-button--success" size="mini">调整客户总量限制</el-button>
        <el-button v-hasPermi="['teamUserManager:batchForceCloseData']" @click="batchForceCloseData(1)"
          class="el-button--danger" size="mini">强制关闭数据接收</el-button>
        <el-button v-hasPermi="['teamUserManager:batchForceCloseData']" @click="batchForceCloseData(0)"
          class="el-button--success" size="mini">解锁数据接收</el-button>
        <el-button v-hasPermi="['teamUserManager:batchSetMonthMaxZerovisits']" @click="batchSetMonthMaxZerovisits"
          class="el-button--success" size="mini">调整月上门挂蛋次数上限</el-button>
      </el-col>
    </el-row>
    <el-row style="margin-top: 10px">
      <el-col :span="24">
        <el-card class="openopenopen" v-show="resMap.isFetchConfigOpen == 1">
          <div><span>数据抓取规则（点击天数进行修改）：</span></div>
          <div><span>规则1：</span>待签约数据超过
            <span style="cursor:pointer;font-size: 16px;font-weight: bold;"
              @click="setFetchDaysConfig('1', 'auto.fetch.cust.tobesigned.days', resMap.fetchDays1)">{{ resMap.fetchDays1
              }}</span>天未跟进就抓取至公共池。
          </div>
          <div><span>规则2：</span>已上门及已签约及已放款超过<span style="cursor:pointer;font-size: 16px;font-weight: bold;"
              @click="setFetchDaysConfig('2', 'auto.fetch.cust.visitsigned.days', resMap.fetchDays2)">{{ resMap.fetchDays2
              }}</span>天未跟进就抓取至公共池。</div>
          <div><span>规则3：</span>再分配和必跟进池客户不管备注搜索状态超过<span style="cursor:pointer;font-size: 16px;font-weight: bold;"
              @click="setFetchDaysConfig('3', 'auto.fetch.cust.must.days', resMap.fetchDays3)">{{ resMap.fetchDays3
              }}</span>天未跟进就抓取至公共池。</div>
          <div><span>规则4：</span>跟进中超过<span style="cursor:pointer;font-size: 16px;font-weight: bold;"
              @click="setFetchDaysConfig('4', 'auto.fetch.cust.follow.days', resMap.fetchDays4)">{{ resMap.fetchDays4
              }}</span>天未跟进就抓取至公共池。</div>
          <div><span>规则5：</span>离职人员客户超过<span style="cursor:pointer;font-size: 16px;font-weight: bold;"
              @click="setFetchDaysConfig('5', 'auto.fetch.cust.quit.days', resMap.fetchDays5)">{{ resMap.fetchDays5
              }}</span>天未被分配就抓取至公共池。</div>
        </el-card>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="userList" show-summary :summary-method="getSummaries"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" min-width="3%">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" prop="nickName" />
      <el-table-column label="部门归属" prop="deptId">
        <template slot-scope="scope">
          {{ getDeptByOrgId(scope.row.deptId) }}
        </template>
      </el-table-column>
      <el-table-column label="日分配数据量" align="center" prop="receiveDaylimit" />
      <el-table-column label="日实际分配" align="center" prop="receiveDayReal" />
      <el-table-column label="接收新数据" align="center" prop="receiveNew">
        <template slot-scope="scope">
          <span v-show="scope.row.receiveNew == null || scope.row.receiveNew == undefined || scope.row.receiveNew == ''"
            class="el-tag el-tag--danger el-tag--medium el-tag--light">不接收</span>
          <dict-tag :options="dict.type.crm_receive" :value="scope.row.receiveNew" />
        </template>
      </el-table-column>
      <el-table-column label="接收公共池数据" align="center" prop="receiveCommon">
        <template slot-scope="scope">
          <span
            v-show="scope.row.receiveCommon == null || scope.row.receiveCommon == undefined || scope.row.receiveCommon == ''"
            class="el-tag el-tag--danger el-tag--medium el-tag--light">不接收</span>
          <dict-tag :options="dict.type.crm_receive" :value="scope.row.receiveCommon" />
        </template>
      </el-table-column>
      <el-table-column label="上次关闭人" align="center" prop="lastLockBy">
        <template slot-scope="scope">
          {{ getNameByEmpId(scope.row.lastLockBy) }}
        </template>
      </el-table-column>

      <el-table-column label="禁止登录" align="center" prop="status">
        <template slot-scope="scope">
          <span v-show="scope.row.status == null || scope.row.status == undefined || scope.row.status == ''"
            class="el-tag el-tag--danger el-tag--medium el-tag--light">已禁止</span>
          <dict-tag :options="dict.type.crm_prohibit" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="自动抓取 " align="center" prop="dataFetchPause">
        <template slot-scope="scope">
          <span
            v-show="scope.row.dataFetchPause == null || scope.row.dataFetchPause == undefined || scope.row.dataFetchPause == ''"
            class="el-tag el-tag--danger el-tag--medium el-tag--light">已暂停</span>
          <dict-tag :options="dict.type.crm_open" :value="scope.row.dataFetchPause" />
        </template>
      </el-table-column>
      <el-table-column label="客户总量限制" align="center" prop="receiveTotallimit" />
      <el-table-column label="强制关闭数据" align="center" prop="isForceClose">
        <template slot-scope="scope">

          <span v-show="scope.row.isForceClose == '1'"
            class="el-tag el-tag--success el-tag--medium el-tag--light">是</span>
          <span v-show="scope.row.isForceClose != '1'" class="el-tag el-tag--danger el-tag--medium el-tag--light">否</span>

        </template>
      </el-table-column>
      <el-table-column label="自助接收按钮" align="center" prop="selfReceiveFlag">
        <template slot-scope="scope">
          <span
            v-show="scope.row.selfReceiveFlag == null || scope.row.selfReceiveFlag == undefined || scope.row.selfReceiveFlag == ''"
            class="el-tag el-tag--danger el-tag--medium el-tag--light">关闭</span>
          <dict-tag :options="dict.type.crm_allow" :value="scope.row.selfReceiveFlag" />
        </template>
      </el-table-column>
      <el-table-column label="自助暂停按钮" align="center" prop="selfCloseFlag">
        <template slot-scope="scope">
          <span v-show="scope.row.selfCloseFlag == '1'"
            class="el-tag el-tag--success el-tag--medium el-tag--light">允许</span>
          <span v-show="scope.row.selfCloseFlag != '1'"
            class="el-tag el-tag--danger el-tag--medium el-tag--light">关闭</span>
        </template>
      </el-table-column>
      <el-table-column label="是否打开了自助接收" align="center" prop="selfReceiveStatus">
        <template slot-scope="scope">
          <span
            v-show="scope.row.selfReceiveStatus == null || scope.row.selfReceiveStatus == undefined || scope.row.selfReceiveStatus == ''"
            class="el-tag el-tag--danger el-tag--medium el-tag--light">否</span>
          <dict-tag :options="dict.type.crm_has" :value="scope.row.selfReceiveStatus" />
        </template>
      </el-table-column>
      <el-table-column label="每月上门挂蛋次数上限" align="center" prop="monthMaxZerovisits" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="修改数据接收配置" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="155px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="姓名" prop="nickName">
              {{ this.form.nickName }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="部门归属" prop="deptId">
              {{ getDeptByOrgId(this.form.deptId) }}
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="手机号" prop="phonenumber">
              {{ this.form.phonenumber }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="日分配数据量" prop="receiveDaylimit">
              <el-input v-model.number="form.receiveDaylimit" placeholder="请输入日分配数据量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="接收额度范围" prop="receiveContion">
              <el-select v-model="queryParams.receiveContion" placeholder="不限额度" filterable clearable>
                <el-option label="不限额" value="0"></el-option>
                <el-option label="3W内" value="1"></el-option>
                <el-option label="5W内" value="2"></el-option>
                <el-option label="10W内" value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户数据总量限制	" prop="receiveTotallimit">
              <el-input v-model.number="form.receiveTotallimit" placeholder="请输入客户数据总量限制	" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="8">
            <el-form-item label="是否接收数据" prop="receiveNew">
              <el-radio-group v-model="form.receiveNew">
                <el-radio-button :label="1">接收</el-radio-button>
                <el-radio-button :label="0">不接收</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="是否接收公共池数据" prop="receiveCommon">
              <el-radio-group v-model="form.receiveCommon">
                <el-radio-button :label="1">接收</el-radio-button>
                <el-radio-button :label="0">不接收</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否禁止登录" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio-button :label="1">是</el-radio-button>
                <el-radio-button :label="0">否</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="是否开启自动抓取数据" prop="dataFetchPause">
              <el-radio-group v-model="form.dataFetchPause">
                <el-radio-button :label="1">是</el-radio-button>
                <el-radio-button :label="0">否</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" align="center">
            <el-form-item>
              <el-button type="primary" size="mini" @click="submitForm">保存</el-button>
              <el-button type="danger" size="mini" @click="cancel">关闭</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getUser, delUser, addUser, updateUser, childrenAlldeptTree, teamUserManager, updateUserByIds } from "@/api/system/user";
import {
  getAllDeptandUsers
} from "@/api/crmsys/custinfo/custinfo";
import {
  updateByKey
} from "@/api/system/config";



import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";


export default {
  name: "Team",
  components: { Treeselect },
  dicts: [
    "crm_yesno",
    "crm_has",
    "crm_allow",
    "crm_prohibit",
    "crm_open",
    "crm_receive",
  ],
  data() {
    return {
      queryParams: {
        roleKey: null,
        receiveNew: null,
        isForceClose: null,
        deptId: null,
        userId: null,
      },
      resMap: {},
      user: { selfReceiveStatus: null, userIds: [] },
      deptOptions: [],
      sysUsersList: [],
      callPhoneText: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        receiveDaylimit: [{ type: 'number', message: '必须为数字值' }],
        dayReceivedCount: [{ type: 'number', message: '必须为数字值' }],
        receiveTotallimit: [{ type: 'number', message: '必须为数字值' }],
      }
    };
  },
  created() {
    this.getList();
    this.getDeptTree();
    this.getDeptAndUsers();
  },
  methods: {
    /** 查询用户信息列表 */
    getList() {
      this.loading = true;
      teamUserManager(this.queryParams).then(response => {
        this.userList = response.data.list.rows;
        this.total = response.data.list.total;
        this.loading = false;
        this.resMap = response.data.resMap;
        if (this.resMap.callphone_func_is_open == "1") {
          this.callPhoneText = "关闭外呼功能";
        } else {
          this.callPhoneText = "打开外呼功能";
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userId = row.userId || this.ids
      teamUserManager({userId:userId}).then(response => {
        this.form = response.data.list.rows[0];
        this.open = true;
        this.title = "修改用户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.userId != null) {
            this.form.userIds=this.form.userId;
            updateUserByIds(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$modal.confirm('是否确认删除用户信息编号为"' + userIds + '"的数据项？').then(function () {
        return delUser(userIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    },
    /** 查询部门归属下拉树结构 */
    getDeptTree() {
      var dept = { deptId: this.$store.state.user.deptid }
      childrenAlldeptTree(dept).then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 获取部门归属和人员信息 */
    getDeptAndUsers() {
      getAllDeptandUsers().then((response) => {
        this.sysUsersList = response.data.sysUsersList;
      });
    },
    setCallOutFuncConfig() {
      this.$modal
        .confirm('确认"' + this.callPhoneText + '"')
        .then(
          () => {
            this.resetUser();
            let configValue2 = this.resMap.callphone_func_is_open == "0" ? "1" : "0";
            updateByKey({ configKey: "CALLPHONE_FUNC_IS_OPEN", configValue: configValue2 }).then((response) => {
              this.$modal.msgSuccess("设置成功");
              this.resMap.callphone_func_is_open = configValue2;
              if (this.resMap.callphone_func_is_open == "1") {
                this.callPhoneText = "关闭外呼功能";
              } else {
                this.callPhoneText = "打开外呼功能";
              }
            })
          }
        )

    },
    batchDealSelfReceiveFlag(status) {
      //更新所选用户的自助接收数据按钮
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      let message = status == 1 ? "打开所选用户的自助接收数据按钮" : "关闭所选用户的自助接收数据按钮";
      this.user.userIds = this.ids;
      this.user.selfReceiveStatus = status;
      console.log(this.user);
      this.$modal
        .confirm('确认"' + message + '"')
        .then(() => {
          updateUserByIds(this.user).then(response => {
            console.log(response);
            if (response.code == 200) {
              this.$modal.msgSuccess("设置成功");
            } else {
              this.$message.error("设置失败");
            }
          });
        });
    },
    batchSetDailyLimit() {
      //调整日分配量
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      this.$prompt('请输入客户日分配量', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^[0-9]*$/,
        inputErrorMessage: '请输入数字'
      }).then(({ value }) => {
        this.user.userIds = this.ids;
        this.user.receiveDaylimit = value;
        updateUserByIds(this.user).then(response => {
          if (response.code == 200) {
            this.$modal.msgSuccess("设置成功");
            this.getList();
          } else {
            this.$message.error("设置失败");
          }
        });
      });
    },
    batchDealSelfCloseFlag(status) {
      //更新所选用户的自助接收数据按钮
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      var message = status == 1 ? "打开所选用户的自助暂停数据按钮" : "关闭所选用户的自助暂停数据按钮";
      this.user.userIds = this.ids;
      this.user.selfCloseFlag = status;
      this.$modal
        .confirm('确认"' + message + '"')
        .then(() => {
          updateUserByIds(this.user).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess("设置成功");
              this.getList();
            } else {
              this.$message.error("设置失败");
            }
          });
        });
    },
    batchDealStatus(status) {
      //用户禁止登录设置
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      var message = status == 1 ? "设置所选用户禁止登录" : "设置所选用户允许登录";
      this.user.userIds = this.ids;
      this.user.status = status;
      this.$modal
        .confirm('确认"' + message + '"')
        .then(() => {
          updateUserByIds(this.user).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess("设置成功");
              this.getList();
            } else {
              this.$message.error("设置失败");
            }
          });
        });
    },
    batchDealReceive(status) {
      //更新所选用户关闭接收数据
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      var message = status == 1 ? "设置所选用户开启接收数据(强制关闭接收的除外)" : "设置所选用户关闭接收数据";
      this.user.userIds = this.ids;
      this.user.receiveNew = status;
      this.$modal
        .confirm('确认"' + message + '"')
        .then(() => {
          updateUserByIds(this.user).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess("设置成功");
              this.getList();
            } else {
              this.$message.error("设置失败");
            }
          });
        });
    },
    batchDealSelfReceiveStatus(status) {
      //所选用户开启自助接收数据
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      var message = status == 1 ? "对所选用户开启自助接收数据" : "对所选用户关闭自助接收数据";
      this.user.userIds = this.ids;
      this.user.selfReceiveStatus = status;
      this.user.receiveNew = status;
      this.$modal
        .confirm('确认"' + message + '"')
        .then(() => {
          updateUserByIds(this.user).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess("设置成功");
              this.getList();
            } else {
              this.$message.error("设置失败");
            }
          });
        });
    },
    batchDealDataFetch(status) {
      //所选用户抓取数据到公共池
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      var message = status == 1 ? "设置所选用户暂停自动抓取数据到公共池" : "设置所选用户开启自动抓取数据到公共池";
      this.user.userIds = this.ids;
      this.user.dataFetchPause = status;
      this.$modal
        .confirm('确认"' + message + '"')
        .then(() => {
          updateUserByIds(this.user).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess("设置成功");
              this.getList();
            } else {
              this.$message.error("设置失败");
            }
          });
        });
    },
    batchSetTotalLimit() {
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      this.$prompt('请输入客户总量限制', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^[0-9]*$/,
        inputErrorMessage: '请输入数字'
      }).then(({ value }) => {
        this.user.userIds = this.ids;
        this.user.receiveTotallimit = value;
        updateUserByIds(this.user).then(response => {
          if (response.code == 200) {
            this.$modal.msgSuccess("设置成功");
            this.getList();
          } else {
            this.$message.error("设置失败");
          }
        });
      });
    },
    batchForceCloseData(status) {
      //所选用户抓取数据到公共池
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      var message = status == 1 ? "强制关闭所选用户的新数据接收" : "解锁所选用户数据接收";
      this.user.userIds = this.ids;
      this.user.isForceClose = status;
      this.user.lastLockBy = this.$store.state.user.id;

      this.$modal
        .confirm('确认"' + message + '"')
        .then(() => {
          updateUserByIds(this.user).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess("设置成功");
              this.getList();
            } else {
              this.$message.error("设置失败");
            }
          });
        });
    },
    batchSetMonthMaxZerovisits() {
      if (this.ids == "") {
        this.$message.error("请选择要操作的记录");
        return;
      }
      this.resetUser();
      this.$prompt('请输入月上门挂蛋次数上限', '挂蛋设置', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^[0-9]*$/,
        inputErrorMessage: '请输入数字'
      }).then(({ value }) => {
        this.user.userIds = this.ids;
        this.user.monthMaxZerovisits = value;
        updateUserByIds(this.user).then(response => {
          if (response.code == 200) {
            this.$modal.msgSuccess("设置成功");
            this.getList();
          } else {
            this.$message.error("设置失败");
          }
        });
      });
    }, setFetchDaysConfig(ruleId, itemKey, days) {
      this.$prompt('请输入规则' + ruleId + '天数：', '天数设置', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^[0-9]*$/,
        inputValue: days,
        inputErrorMessage: '请输入数字'
      }).then(({ value }) => {
        if (value <= 0) {
          this.$message.error("设置失败，天数不能为0！");
          return;
        }
        updateByKey({ configKey: itemKey, configValue: value }).then((response) => {
          if (response.code == 200) {
            this.$modal.msgSuccess("设置成功");
            this.getList();
          } else {
            this.$message.error("设置失败");
          }
        }).catch();

      })
    },
    resetUser() {
      this.user = {
        selfReceiveStatus: null, monthMaxZerovisits: null, isForceClose: null, receiveTotallimit: null, dataFetchPause: null, selfReceiveStatus: null,
        receiveNew: null, status: null, selfCloseFlag: null, userIds: []
      };
    },
    // 对列进行合算
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 3) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (column.property === 'receiveDaylimit' || column.property === 'receiveDayReal') {
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += ' 个';
          } else {
            sums[index] = '---'
          }
        }
      });
      return sums;
    }
  }
};
</script>

<style>
.openopenopen {
  line-height: 1.6;
  padding: 0 10px;
  font-size: 14px;
}

.openopenopen span {
  color: #d93737;
}

.el-col {
  border-radius: 4px;
}
</style>

